
cc.Class({
    extends: cc.Component,

    properties: {
        Fy_FriendsGuessDialects:cc.Node,
        Fy_SelectedDialects:cc.Node,
        HomePage:cc.Node,
        DialectArtists:cc.Node,
        Own:cc.Node,
        BtnHomePage:cc.Button,
        BtnArtist:cc.Button,
        BtnOwn:cc.Button,
        Own_Portrait:cc.Sprite,
        Own_Name:cc.Label,
        Own_Introduce:cc.Label,
        Own_WorksLabel:cc.Label,
        Own_AnswerLabel:cc.Label,
        Da_Node:cc.Prefab,
        content:cc.Node,
        PicModel:cc.Node,
        SlidingLoading:cc.Label
    },
    onLoad:function(){
       this.Fy_FriendsGuessDialects.getComponent("FriendsGuessDialects").onLoadingHead();
       this.BtnHomePage.node.on("click", this.onBtnHomePage, this); 
       this.BtnArtist.node.on("click", this.onBtnArtist, this); 
       this.BtnOwn.node.on("click", this.onBtnOwn, this);
    },
    onClickTakeAGuess(){   // 说方言界面
        window.GameClubButton.hide();
        this.node.active = false;
        this.Fy_FriendsGuessDialects.getComponent("FriendsGuessDialects").info(this.node);
    },
    onSelectedDialects(){  // 方言精选页面
        window.GameClubButton.hide();
        this.node.active = false;
        this.Fy_SelectedDialects.getComponent("SelectedDialects").oninfo();
    },
    onBtnHomePage(){ // 首页
        window.GameClubButton.show();
        this.HomePage.active = true;
        this.DialectArtists.active = false;
        this.Own.active = false;
    },
    onBtnArtist(){   // 排行榜
        window.GameClubButton.hide();
        this.HomePage.active = false;
        this.DialectArtists.active = true;
        this.Own.active = false;
        this.content.removeAllChildren(true);
        this.PicModel.on("bounce-bottom", this.callback, this);//监听滑动到低端
        this.callbackId = 0;
        this.data = [];
        for(var i =0;i<100;i++){
            this.data.push({
                url:UserData.UserInfo.avatarUrl,
                name:UserData.UserInfo.nickName,
                Dialect:"哦有面",
                Answer:"哦有面",
                LikesQuantity:"999"
            })
        }
        this.onLoadArtist(0)
    },
    onLoadArtist(value){
        this.LastNumber = value+20;
        for(var i = value;i<value+20;i++){
            var Barrages = cc.instantiate(this.Da_Node);
            Barrages.getComponent("DialectArtists").init(123,this.data[i]);
            Barrages.y = -(70+i*90);
            Barrages.x = 0;
            this.content.addChild(Barrages);
        };
        this.content.height = 170+(value+19)*90;
        this.SlidingLoading.node.active = false;
        this.callbackId = 0;
    },
    callback() {
         this.callbackId = this.callbackId +1;
         if(this.callbackId == 1){
            this.SlidingLoading.string = "向上滑加载更多";
            this.SlidingLoading.node.active = true;
         }else if(this.callbackId == 2){
            this.callbackId = undefined;
            this.SlidingLoading.string = "正在加载中";
            if(this.LastNumber < 99){
                this.onLoadArtist(this.LastNumber);
            }else{
                this.SlidingLoading.string = "榜单每天最多刷新前100位";
            }
         } 
    },
    onBtnOwn(){      // 展示我的页面
        window.GameClubButton.hide();
        this.onOwnInformation();
        this.HomePage.active = false;
        this.DialectArtists.active = false;
        this.Own.active = true;
    },
    onOwnInformation(){
        var urls = UserData.UserInfo.avatarUrl;
        var self = this;
        cc.loader.load({url: urls, type: 'png'}, function (err, texture) {
            self.Own_Portrait.spriteFrame = new cc.SpriteFrame(texture);
        });
        this.Own_Name.string = UserData.UserInfo.nickName;
        this.Own_Introduce.string = "被回答了7次你的答案获得了1000个赞";
        this.Own_WorksLabel.string = UserData.UserInfo.works;
        this.Own_AnswerLabel.string = UserData.UserInfo.answer;
    }
});
